#!/usr/bin/python
# -*- coding: utf8 -*-
from urllib import urlencode
import urllib2
"""Classe pour récuperer une page directement en un clin d'oeil !"""
class getpage:
    def __init__(self, base, params):
        param=self.unicode_urlencode(params)
        url=base+param
        global url

    def get(self):
        request_headers = { 'User-Agent': 'PeekABoo/1.3.7' }
        request = urllib2.Request(url, None, request_headers)
        urlfile = urllib2.urlopen(request)
        return urlfile.read()

    def unicode_urlencode(self, params):
        # Urlencode version uncode !
        if isinstance(params, dict):
            params = params.items()
            return urlencode([(k, isinstance(v, unicode) and v.encode('utf-8') or v) 
                          for k, v in params])